home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / DRIVES.SWG / 0055_Disk Serial Number in ASM.pas < prev    next >
Pascal/Delphi Source File  |  1993-11-02  |  2KB  |  89 lines

  1. {
  2. jimisola.laursen@cindy.ct.se (jimisola laursen)
  3.  
  4. > Anybody know how to read the Volume Serial Number from a (hard) disk??
  5. > No problem getting the Volume Label, but this seemsa to be another matter...
  6. }
  7.  
  8. Unit Serial;
  9.  
  10. Interface
  11.  
  12. Uses
  13.   Dos;
  14.  
  15. Function Get_Serial_number(Drive : Byte) : String;
  16.  
  17. Implementation
  18.  
  19. Asm
  20.   mov  ax, w
  21.   mov  bx, b
  22.   xor  cx, cx
  23.   les  di, @result
  24.   xor  si, si
  25.   jcxz @@@20
  26.  @@@10:
  27.   xor  dx, dx
  28.   div  bx
  29.   cmp  dl, 10
  30.   jb   @h10
  31.   add  dl, 'A'-10
  32.   jmp  @h20
  33.  @h10:
  34.    or  dl, '0'
  35.  @h20:
  36.   push dx
  37.   inc  si
  38.   loop @@@10
  39.  @@@20:
  40.   inc  cx
  41.   or   ax, ax
  42.   jnz  @@@10
  43.   mov  cx, si
  44.   jcxz @@@40
  45.   cld
  46.   mov  al, cl
  47.   stosb
  48.  @@@30:
  49.   pop  ax
  50.   stosb
  51.   loop @@@30
  52.  @@@40:
  53. end;
  54.  
  55. Function Get_Serial_number(Drive : Byte) : String;
  56. (* "Drive" is 0=current, 1=A:, 2=B: osv.. *)
  57. Type
  58.   Disk_info = Record
  59.     RES     : Word;                 (* reserverad ska Vara 0 *)
  60.     SER_NR1 : Word;                 (* Serinummer (bin{rt) *)
  61.     SER_NR2 : Word;                 (* Serinummer (bin{rt) *)
  62.     VOL     : Array [1..11] of Char;(* Volume Label *)
  63.     TYP     : Array [1..8] of Char; (* tex 'FAT12' eller 'FAT16' *)
  64.   end;
  65. Var
  66.    D_I    : Disk_Info;
  67.    s1, s2 : String[5];
  68. begin
  69.   Asm
  70.     push ds
  71.     mov ax,ss
  72.     mov ds,ax
  73.     lea dx,D_I
  74.     mov bl,drive
  75.     mov ax,6900h
  76.     int 21h
  77.     pop ds
  78.   end;
  79.   s1 := NumAscii(D_I.SER_NR2, 16);
  80.   s2 := NumAscii(D_I.SER_NR1, 16);
  81.   While length(s1) < 4 do
  82.     s1 := '0' + s1;
  83.   While length(s2) < 4 do
  84.     s2 := '0' + s2;
  85.   Get_Serial_number := s1 + '-' + s2;
  86. end;
  87.  
  88. end.
  89.